<template>
<div>

  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>系统管理</el-breadcrumb-item>
    <el-breadcrumb-item>角色管理</el-breadcrumb-item>
  </el-breadcrumb>

  <el-card style="margin-top: 2%">
    <el-input style="width: 20%"
              placeholder="请输入名称"
              v-model="role.rolename">
    </el-input>
    <el-input style="width: 20%"
              size="medium"
              placeholder="请输入编码"
              v-model="role.rolecode">
    </el-input>
    <el-input style="width: 20%"
              size="medium"
              placeholder="请输入用户id"
              v-model="role.id">
    </el-input>
    <el-button type="primary">搜索</el-button>
    <el-button type="primary"@click="dialogVisible = true">添加</el-button>

    <hr style="border: 1px;background-color: red"/>
    <el-table   :header-cell-style="{background:'darkcyan',color:'white'}"
      :data="role" :border="true"
      style="width: 100%; ">
      <el-table-column
        label="roleid"
        prop="roleid">

      </el-table-column>

      <el-table-column label="角色名称" prop="rolename">

      </el-table-column>
      <el-table-column label="角色编码" prop="rolecode">

      </el-table-column>
      <el-table-column label="描述" prop="remark">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination style="margin-top: 15px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[1, 2, 5, 10]"
      :page-size="queryInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totol">
    </el-pagination>

    <el-dialog
      title="添加用户"
      :visible.sync="dialogVisible"

      width="50%"

      style="height: 100%"
    center>

<!--      <AddUser @closeDialog="handleclose"></AddUser>-->

    </el-dialog>
  </el-card>




</div>
</template>

<script>
import instance from "../../utils/request";

export default {
  name: "RoleList",
  // components: {AddUser},

  data() {
    return {
      dialogVisible: false,
      role:[{
        id:'',
        rolename:'',
        rolecode:'',
        remark:'',
      }],

      //获取用户列表的参数对象
      queryInfo:{
        query:'',
        pagenum:1,
        pageSize:2
      },
      totol:0,

      show:true,
    }
  },
  methods: {
    toAdd(){
      false;
    },

    //监听pagesize改变的事件
    handleSizeChange(newSize){
      this.queryInfo.pageSize = newSize;
      this.getRoleList();
      console.log(newSize);

    },

    //监听页码值改变的事件
    handleCurrentChange(newPage){
      this.queryInfo.pagenum = newPage;
      this.getRoleList();

    },

    handleclose() {
      console.log(12345);
      this.dialogVisible = false;
    },

    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    findPage(page){
      console.log(page);
    },
    findSize(size){
      console.log(size);
    },
    addUser(){
    },

    getRoleList(){
      instance.get("/role/getrole",{params:this.queryInfo}).then(res=>{
        this.role = res.data.list;
        this.totol = res.data.totol;
        return this.user;
      }).catch(err=>{
        alert("后台服务器错误");

      })
    }

  },


  created() {

    this.getRoleList();
  }
}
</script>

<style>
.transition-box {
  margin-bottom: 10px;
  width: 200px;
  height: 100px;
  border-radius: 4px;
  background-color: #409EFF;
  text-align: center;
  color: #fff;
  padding: 40px 20px;
  box-sizing: border-box;
  margin-right: 20px;
}
</style>
